from  app import create_app
from app.libs.error import APIException
from werkzeug.exceptions import HTTPException

from app.libs.error_code import ServerError

app=create_app()

@app.errorhandler(Exception)
def framework_error(e):#统一处理所有异常
    if isinstance(e,APIException):
        return e
    if isinstance(e,HTTPException):
        code=e.code
        msg=e.description
        error_code=1007
        return APIException(msg,code,error_code)
    else:
        #log 未知错误
        #调试模式 开启就返回没处理过的原始异常
        if not app.config['DEBUG']:
            return ServerError()
        else:
            raise e




if __name__ == '__main__':
    app.run(debug=True)
    # app.run(debug=True,port="7936",host='0.0.0.0')